﻿using Autofac;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace NiuBeService
{
    public class AutofacHelper
    {
        private static readonly ContainerBuilder builder;
        public static IEnumerable<IJob> Jobs { get; set; }
        /// <summary>
        /// AutoFac注册全局Job
        /// </summary>
        static AutofacHelper()
        {
            builder = new ContainerBuilder();
            builder
                .RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
                .AsImplementedInterfaces()
                .AsSelf();
            var container = builder.Build();
            Jobs = container.Resolve<IEnumerable<IJob>>();
        }
        /// <summary>
        /// 获取IJob
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        public static Type GetAssemlyJobs(string jobName)
        {
            return Jobs?.FirstOrDefault(o => o.GetType().Name.ToLower() == jobName.Trim().ToLower())?.GetType();
        }
    }
}
